from flask import Blueprint, request, jsonify
from service.nw_pz.nw_pz_service import get_pagedata, get_pzk, get_pzfl, get_fzys

# app = Flask(__name__)
# 创建 Blueprint
nw_pz_blueprint = Blueprint('nw_pz', __name__)


# 获取分页记录
@nw_pz_blueprint.route('/api/pagedata', methods=['POST'])
def get_pagedata_controller():
    try:
        data = request.get_json()
        dwbh = data.get('dwbh')
        ledger = data.get('ledger')
        model = data.get('model')
        qzq_type = data.get('qzq_type')
        pageNum = data.get('pageNum')
        pageSize = data.get('pageSize')
        search = data.get('search')
        print(dwbh, ledger, pageNum, pageSize, search)
        data, total_count = get_pagedata(dwbh, ledger, model, qzq_type, search, pageNum, pageSize)
        return jsonify({"code":200,"pageNum":pageNum,"pageSize":pageSize,"total":total_count, "data":data}), 200
    except Exception as e:
        return jsonify({"error": str(e)}), 500

@nw_pz_blueprint.route('/api/pzk', methods=['POST'])
def get_pzk_controller():
    try:
        data = request.get_json()
        dwbh = data.get('dwbh')
        ledger = data.get('ledger')
        kjnd = data.get('kjnd')
        kjqj = data.get('kjqj')
        pzbh = data.get('pzbh')
        print(dwbh, ledger, kjnd, kjqj, pzbh)
        data = get_pzk(dwbh, ledger, kjnd, kjqj, pzbh)
        return jsonify({"code":200,"data":data}), 200
    except Exception as e:
        return jsonify({"error": str(e)}), 500

@nw_pz_blueprint.route('/api/pzfl', methods=['POST'])
def get_pzfl_controller():
    try:
        data = request.get_json()
        dwbh = data.get('dwbh')
        ledger = data.get('ledger')
        kjnd = data.get('kjnd')
        pzid = data.get('pzid')
        kmtx = data.get('kmtx')
        print(dwbh, ledger, kjnd, pzid, kmtx)
        data = get_pzfl(dwbh, ledger, kjnd, pzid, kmtx)
        return jsonify({"code": 200, "data": data}), 200
    except Exception as e:
        return jsonify({"error": str(e)}), 500

@nw_pz_blueprint.route('/api/fzys', methods=['POST'])
def get_fzys_controller():
    try:
        data = request.get_json()
        dwbh = data.get('dwbh')
        ledger = data.get('ledger')
        kjnd = data.get('kjnd')
        pzid = data.get('pzid')
        flid = data.get('flid')
        search = data.get('search')
        pageNum = data.get('pageNum')
        pageSize = data.get('pageSize')
        # p_dwbh, p_ledger, p_kjnd, p_pzid, p_flid, search, p_page = 1, p_pageSize = 10
        print(dwbh, ledger, kjnd, pzid, flid, search, pageNum, pageSize)
        data, total_count = get_fzys(dwbh, ledger, kjnd, pzid, flid, search, pageNum, pageSize)
        return jsonify({"code":200,"pageNum":pageNum,"pageSize":pageSize,"total":total_count, "data":data}), 200
    except Exception as e:
        return jsonify({"error": str(e)}), 500